﻿using Airborne.ScrumPoker.Module.ProductOwner.Views;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;

namespace Airborne.ScrumPoker.Module.ProductOwner
{
    public class ProjectOwnerModule : IModule
    {
        private IUnityContainer Container { get; set; }
        private IRegionManager RegionManager { get; set; }


        public ProjectOwnerModule(IUnityContainer container, IRegionManager regionManager)
        {
            Container = container;
            RegionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterComponents();

            IProjectOwnerView projectOwnerView = Container.Resolve<IProjectOwnerView>();

            RegionManager.Regions[RegionNames.MainRegion].Add(projectOwnerView);
            RegionManager.Regions[RegionNames.MainRegion].Activate(projectOwnerView);

            Controller.IProjectOwnerController projectOwnerController = Container.Resolve<Controller.IProjectOwnerController>();
            projectOwnerController.Run();
        }

        private void RegisterComponents()
        {
            
           // Container.RegisterType<Controller.IVotingResultController, Controller.VotingResultController>(new ExternallyControlledLifetimeManager());
            Container.RegisterType<Controller.IProjectOwnerController, Controller.ProjectOwnerController>(new ExternallyControlledLifetimeManager());
            Container.RegisterType<IWorkItemDetailsView, WorkItemDetailView>(new ExternallyControlledLifetimeManager());
            Container.RegisterType<ITimerDetailView, TimerDetailView>(new ExternallyControlledLifetimeManager());
            Container.RegisterType<IPlayerDetailView, PlayerDetailView>(new ExternallyControlledLifetimeManager());
            Container.RegisterType<IProjectOwnerView, ProjectOwnerView>(new ExternallyControlledLifetimeManager());
        }

        #endregion
    }
}
